<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>fd-limit</title>
</head>
<body>
  <script>
  var gui = require('nw.gui');
  var nw = require('../nw');

  get2k();

  function get2k() {
    var pass = false;
    var count = 2000;
    for(var i = 0; i < count; i++) {
        getFile('../testfiles/'+i+'.json', done);
    }

    function done(err) {
      if (pass) return;
      if (err) {
        pass = true;
        reportDone(false);
      } else if (--count === 0) {
        reportDone(true);
      }
    }
  }

  function getFile(file, done) {
      var xhr = new XMLHttpRequest();
      xhr.onload = function(){done();};
      xhr.onerror = function(){done(true);};
      xhr.open('GET', file, true);
      xhr.send();
  }

  function reportDone(result) {
    console.log(result);
    nw.send({ok: result});
  }
  </script>
</body>
</html>
